
function  groupResult(data){
    const newDataObj = {};

    let newDataArr = [...data];

    do {
        const newElem = newDataArr.shift()
        const theMatches = newDataArr.filter(it => it.ID === newElem.ID);
        if (theMatches.length) {
            theMatches.forEach((it, index) => {
                it.haveDuple = true
                if (newDataObj[`group ${index + 2}`]) {
                    newDataObj[`group ${index + 2}`].push(it)
                } else {
                    newDataObj[`group ${index + 2}`] = [it]
                }
            });
            newElem.haveDuple = true;
        }
        if (newDataObj['group 1']) {
            newDataObj['group 1'].push(newElem)
        } else {
            newDataObj['group 1'] = [newElem]
        }
        newDataArr = newDataArr.filter(it => it.ID !== newElem.ID);
    } while (newDataArr.length)

    return newDataObj
}

module.exports = {groupResult}